package edu.scsw.tech.unit2;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Rectangle {

    public static void main(String[] args) {
        // 创建一个Scanner对象来读取用户输入
        try (Scanner scanner = new Scanner(System.in)) {
            // 提示用户输入矩形的宽度
            System.out.print("请输入矩形的宽度: ");
            int width = scanner.nextInt();

            // 提示用户输入矩形的高度
            System.out.print("请输入矩形的高度: ");
            int height = scanner.nextInt();

            // 计算矩形的面积和周长
            int area = width * height;
            int perimeter = 2 * (width + height);

            // 输出结果
            System.out.println("矩形的面积是: " + area);
            System.out.println("矩形的周长是: " + perimeter);
        } catch (InputMismatchException e) {
            System.out.println("输入有误，请重试！");
        } catch (Exception e) {
            System.out.println("出现异常，请重试！");
        }
    }
}

